<?php

require_once('Zend/Queue/Message.php');

class Myzen_Queue_AsynchronousJobMessage extends Zend_Queue_Message
{
    protected $_module = '';
    protected $_controller = '';	
    protected $_action = '';
    protected $_params = array();
    /**
     * We adjusted the constructor to accept both an array and an object.
     */
    public function __construct($mixed,$controller = '',$action = '',$params = array()) {
        // we still have to support the code in Zend_Queue::receive that
        // passes in an array
        if(is_array($mixed)) {
			parent::__construct($mixed);
			Zend_Registry::get('dt_log')->log('looks like the message has been called from receive',7);
			$data = @unserialize($mixed['data']['body']);
			if(!$data) {
				require_once('Zend/Queue/Exception.php');
				throw new Zend_Queue_Exception('Issue occured while deserializing the message in AsynchronousJobMessage',154);
			}
			if(empty($data['module']) || empty($data['controller']) || empty($data['action'])){
				require_once('Zend/Queue/Exception.php');
				throw new Zend_Queue_Exception('Missing module or controller or action in AsynchronousJobMessage',155);
			}
			$this->_module = $data['module'];
			$this->_controller = $data['controller'];
			$this->_action = $data['action'];
			$this->_params = $data['params'];
		}
		elseif(is_string($mixed) && !empty($controller) && !empty($action)) {
			$this->_module = $mixed;
			$this->_controller = $controller;
			$this->_action = $action;
			if(is_array($params)) $this->_params = $params;
        }
		//Zend_Registry::get('dt_log')->log('asynchronous message called:'.serialize($mixed),7);
    }

	
	public function getModule() {
		return $this->_module;
	}
	public function getController() {
		return $this->_controller;
	}
	public function getAction() {
		return $this->_action;
	}
	public function getParams() {
		return $this->_params;
	}
    /**
     * We need to get the underlying body as a string
     *
     * @return string
     */
    public function __toString() {
        $data = array(
			'module' => $this->_module,
			'controller' => $this->_controller,	
			'action' => $this->_action,
			'params' => $this->_params
		);
		return serialize($data);
    }

    /**
     * Sets the message body
     *
     * @param serializable $mixed
     */
    /*
	public function setBody($mixed)
    {
        $this->_data['body'] = serialize($mixed);
    }
	*/
    /**
     * Gets the message body
     *
     * @return $mixed
     */
    /*
	public function getBody()
    {
        return unserialize($this->_data['body']);
    }
	*/

}
